import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';

class HttpPaymentService {
  static Future<Response> paymentList(
      {String startDate, String endDate, String accountId}) {
    return BaseConfig.httpBase.get('/api/payments', {
      'start_date': startDate,
      'end_date': endDate,
      'account_id': accountId,
    });
  }

  /// new cash in
  static Future<Response> paymentCashIn({
    int contact_id,
    String type,
    String number,
    int account_id,
    int payment_type_id,
    int tax_id,
    int is_tax_inclusive,
    num tax_amount,
    String issued_at,
    String currency_code,
    String total,
    String cheque_number,
    List numbers,
    List number_ids,
    String account_total,
    String notes,
    List attachment_ids,
  }) {
    return BaseConfig.httpBase.postJson('/api/payments/cash_in', {
      "contact_id": contact_id,
      "number": number,
      "flow_type": "in",
      "type": type,
      "account_id": account_id,
      "payment_type_id": payment_type_id,
      "tax_id": tax_id,
      "is_tax_inclusive": is_tax_inclusive,
      "tax_amount": tax_amount,
      "issued_at": issued_at,
      "currency_code": currency_code,
      "total": total,
      "account_total": account_total,
      "cheque_number": cheque_number,
      "numbers": numbers,
      'number_ids': number_ids,
      'notes': notes,
      'attachment_ids': attachment_ids ?? [],
    });
  }

  static Future<Response> paymentUpdateCashIn(
    int id, {
    int contact_id,
    String number,
    String type,
    int account_id,
    int payment_type_id,
    int tax_id,
    int is_tax_inclusive,
    num tax_amount,
    String issued_at,
    String currency_code,
    String total,
    String cheque_number,
    List numbers,
    List number_ids,
    String account_total,
    String notes,
    List attachment_ids,
  }) {
    return BaseConfig.httpBase.putJson('/api/payments/$id', {
      "contact_id": contact_id,
      "number": number,
      "flow_type": "in",
      "type": type,
      "account_id": account_id,
      "payment_type_id": payment_type_id,
      "tax_id": tax_id,
      "is_tax_inclusive": is_tax_inclusive,
      "tax_amount": tax_amount,
      "issued_at": issued_at,
      "currency_code": currency_code,
      "total": total,
      "account_total": account_total,
      "cheque_number": cheque_number,
      "numbers": numbers,
      'number_ids': number_ids,
      'notes': notes,
      'attachment_ids': attachment_ids ?? [],
    });
  }

  /// 查询 cash in 的信息
  static Future<Response> paymentCashOut({
    int contact_id,
    String number,
    String type,
    int account_id,
    int payment_type_id,
    int tax_id,
    int is_tax_inclusive,
    num tax_amount,
    String issued_at,
    String currency_code,
    String total,
    String account_total,
    String cheque_number,
    List numbers,
    List numberIds,
    String notes,
    List attachment_ids,
  }) {
    return BaseConfig.httpBase.postJson('/api/payments/cash_out', {
      "contact_id": contact_id,
      "number": number,
      "flow_type": "out",
      "type": type,
      "account_id": account_id,
      "payment_type_id": payment_type_id,
      "tax_id": tax_id,
      "is_tax_inclusive": is_tax_inclusive,
      "tax_amount": tax_amount,
      "issued_at": issued_at,
      "currency_code": currency_code,
      "total": total,
      "account_total": account_total,
      "cheque_number": cheque_number,
      "numbers": numbers,
      'number_ids': numberIds,
      'notes': notes,
      'attachment_ids': attachment_ids ?? [],
    });
  }

  static Future<Response> paymentUpdateCashOut(
    int id, {
    int contact_id,
    String number,
    String type,
    int account_id,
    int payment_type_id,
    int tax_id,
    int is_tax_inclusive,
    num tax_amount,
    String issued_at,
    String currency_code,
    String total,
    String account_total,
    String cheque_number,
    List numbers,
    List numberIds,
    String notes,
    List attachment_ids,
  }) {
    return BaseConfig.httpBase.putJson('/api/payments/$id', {
      "contact_id": contact_id,
      "number": number,
      "flow_type": "out",
      "type": type,
      "account_id": account_id,
      "payment_type_id": payment_type_id,
      "tax_id": tax_id,
      "is_tax_inclusive": is_tax_inclusive,
      "tax_amount": tax_amount,
      "issued_at": issued_at,
      "currency_code": currency_code,
      "total": total,
      "account_total": account_total,
      "cheque_number": cheque_number,
      "numbers": numbers,
      'number_ids': numberIds,
      'notes': notes,
      'attachment_ids': attachment_ids ?? [],
    });
  }

  /// 查询 credit Notes 的信息
  static Future<Response> paymentCreditNotes() {
    return BaseConfig.httpBase.postJson('/api/payments/credit_notes', {});
  }

  static Future<Response> showPayment(int id) {
    return BaseConfig.httpBase.get('/api/payments/$id', {});
  }

  static Future<Response> deletePayment(int id) {
    return BaseConfig.httpBase.deleteJson('/api/payments/$id', {});
  }

  static Future<Response> deletePayments(List<int> ids) {
    return BaseConfig.httpBase.postJson('/api/payments/batch_delete', {
      'ids': ids,
    });
  }

  /// 查询 credit Notes 的信息
  static Future<Response> paymentTransfer({
    int account_id,
    int to_account_id,
    String issued_at,
    String currency_code,
    double total,
    double to_total,
    int payment_type_id,
    String cheque_number,
    List attachment_ids,
  }) {
    return BaseConfig.httpBase.postJson('/api/payments/transfer', {
      "flow_type": "transfer",
      "type": "transfer",
      "account_id": account_id,
      "to_account_id": to_account_id,
      "issued_at": issued_at,
      "currency_code": currency_code,
      "total": total,
      "to_total": to_total,
      "payment_type_id": payment_type_id,
      "cheque_number": cheque_number,
      'attachment_ids': attachment_ids ?? [],
    });
  }
}
